|
1
|
|
|
const webpack = require('webpack'); |
|
|
|
|
|
|
2
|
|
|
const path = require('path'); |
|
3
|
|
|
const package = require('./package.json'); |
|
|
|
|
|
|
4
|
|
|
const VueLoaderPlugin = require('vue-loader/lib/plugin'); |
|
5
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin'); |
|
|
|
|
|
|
6
|
|
|
const TerserJSPlugin = require('terser-webpack-plugin'); |
|
7
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
|
8
|
|
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); |
|
9
|
|
|
// const config = require( './config.json' ); |
|
10
|
|
|
|
|
11
|
|
|
const devMode = process.env.NODE_ENV !== 'production'; |
|
12
|
|
|
|
|
13
|
|
|
// Naming and path settings |
|
14
|
|
|
var appName = 'wpb'; |
|
|
|
|
|
|
15
|
|
|
var entryPoint = { |
|
16
|
|
|
frontend: './resources/js/frontend/main.js', |
|
17
|
|
|
admin: './resources/js/admin/main.js', |
|
18
|
|
|
spa: './resources/js/spa/main.js', |
|
19
|
|
|
style: './resources/sass/app.scss' |
|
20
|
|
|
}; |
|
21
|
|
|
|
|
22
|
|
|
var exportPath = path.resolve(__dirname, './public/js'); |
|
23
|
|
|
|
|
24
|
|
|
// Enviroment flag |
|
25
|
|
|
var plugins = []; |
|
26
|
|
|
var env = process.env.NODE_ENV; |
|
27
|
|
|
|
|
28
|
|
|
function isProduction() { |
|
29
|
|
|
return process.env.NODE_ENV === 'production'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// extract css into its own file |
|
33
|
|
|
plugins.push(new MiniCssExtractPlugin({ |
|
34
|
|
|
filename: '../css/[name].css', |
|
35
|
|
|
ignoreOrder: false, // Enable to remove warnings about conflicting order |
|
36
|
|
|
})); |
|
37
|
|
|
|
|
38
|
|
|
// plugins.push(new BrowserSyncPlugin( { |
|
39
|
|
|
// proxy: { |
|
40
|
|
|
// target: config.proxyURL |
|
41
|
|
|
// }, |
|
42
|
|
|
// files: [ |
|
43
|
|
|
// '**/*.php' |
|
44
|
|
|
// ], |
|
45
|
|
|
// cors: true, |
|
46
|
|
|
// reloadDelay: 0 |
|
47
|
|
|
// } )); |
|
48
|
|
|
|
|
49
|
|
|
plugins.push(new VueLoaderPlugin()); |
|
50
|
|
|
|
|
51
|
|
|
// Differ settings based on production flag |
|
52
|
|
|
if ( devMode ) { |
|
53
|
|
|
appName = '[name].js'; |
|
54
|
|
|
} else { |
|
55
|
|
|
appName = '[name].min.js'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
module.exports = { |
|
59
|
|
|
entry: entryPoint, |
|
60
|
|
|
mode: devMode ? 'development' : 'production', |
|
61
|
|
|
output: { |
|
62
|
|
|
path: exportPath, |
|
63
|
|
|
filename: appName, |
|
64
|
|
|
}, |
|
65
|
|
|
|
|
66
|
|
|
resolve: { |
|
67
|
|
|
alias: { |
|
68
|
|
|
'vue$': 'vue/dist/vue.esm.js', |
|
69
|
|
|
'@': path.resolve('./resources/'), |
|
70
|
|
|
'frontend': path.resolve('./resources/frontend/'), |
|
71
|
|
|
'admin': path.resolve('./resources/admin/'), |
|
72
|
|
|
'spa': path.resolve('./resources/spa/'), |
|
73
|
|
|
}, |
|
74
|
|
|
modules: [ |
|
75
|
|
|
path.resolve('./node_modules'), |
|
76
|
|
|
path.resolve(path.join(__dirname, 'resources/')), |
|
77
|
|
|
] |
|
78
|
|
|
}, |
|
79
|
|
|
|
|
80
|
|
|
optimization: { |
|
81
|
|
|
runtimeChunk: 'single', |
|
82
|
|
|
splitChunks: { |
|
83
|
|
|
cacheGroups: { |
|
84
|
|
|
vendor: { |
|
85
|
|
|
test: /[\\\/]node_modules[\\\/]/, |
|
86
|
|
|
name: 'vendors', |
|
87
|
|
|
chunks: 'all' |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
}, |
|
91
|
|
|
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})], |
|
92
|
|
|
}, |
|
93
|
|
|
|
|
94
|
|
|
plugins, |
|
95
|
|
|
|
|
96
|
|
|
module: { |
|
97
|
|
|
rules: [ |
|
98
|
|
|
{ |
|
99
|
|
|
test: /\.vue$/, |
|
100
|
|
|
loader: 'vue-loader' |
|
101
|
|
|
}, |
|
102
|
|
|
{ |
|
103
|
|
|
test: /\.js$/, |
|
104
|
|
|
use: 'babel-loader', |
|
105
|
|
|
exclude: /node_modules/ |
|
106
|
|
|
}, |
|
107
|
|
|
{ |
|
108
|
|
|
test: /\.scss$/, |
|
109
|
|
|
use: [ |
|
110
|
|
|
'vue-style-loader', |
|
111
|
|
|
'css-loader', |
|
112
|
|
|
'sass-loader' |
|
113
|
|
|
] |
|
114
|
|
|
}, |
|
115
|
|
|
{ |
|
116
|
|
|
test: /\.less$/, |
|
117
|
|
|
use: [ |
|
118
|
|
|
'vue-style-loader', |
|
119
|
|
|
'css-loader', |
|
120
|
|
|
'less-loader' |
|
121
|
|
|
] |
|
122
|
|
|
}, |
|
123
|
|
|
{ |
|
124
|
|
|
test: /\.png$/, |
|
125
|
|
|
use: [ |
|
126
|
|
|
{ |
|
127
|
|
|
loader: 'url-loader', |
|
128
|
|
|
options: { |
|
129
|
|
|
mimetype: 'image/png' |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
] |
|
133
|
|
|
}, |
|
134
|
|
|
{ |
|
135
|
|
|
test: /\.svg$/, |
|
136
|
|
|
use: 'file-loader' |
|
137
|
|
|
}, |
|
138
|
|
|
{ |
|
139
|
|
|
test: /\.css$/, |
|
140
|
|
|
use: [ |
|
141
|
|
|
{ |
|
142
|
|
|
loader: MiniCssExtractPlugin.loader, |
|
143
|
|
|
options: { |
|
144
|
|
|
publicPath: (resourcePath, context) => { |
|
145
|
|
|
return path.relative(path.dirname(resourcePath), context) + '/'; |
|
146
|
|
|
}, |
|
147
|
|
|
hmr: process.env.NODE_ENV === 'development', |
|
148
|
|
|
}, |
|
149
|
|
|
}, |
|
150
|
|
|
'css-loader', |
|
151
|
|
|
], |
|
152
|
|
|
}, |
|
153
|
|
|
] |
|
154
|
|
|
}, |
|
155
|
|
|
} |